package site.marqstree.latte.ui.recycler;

/*
 * 项目名: EleCommerce
 * 包名: site.marqstree.latte.ui.recycler
 * 文件名: DataConverter
 * 创建者: marqstree
 * 创建时间: 2020/1/22 19:57
 * 描述: json转实体数组工具类
 */

import java.util.ArrayList;

public abstract class DataConverter {

    //实体数组，供BaseRecyclerViewAdapterHelper使用
    protected final ArrayList<MultipleItemEntity> ENTITIES = new ArrayList<>();
    private String mJsonData = null;

    //json转实体数组
    public abstract ArrayList<MultipleItemEntity> convert();

    //构造函数接收json字符串
    public DataConverter setJsonData(String json) {
        this.mJsonData = json;
        return this;
    }

    //取出json字符串
    protected String getJsonData() {
        if (mJsonData == null || mJsonData.isEmpty()) {
            throw new NullPointerException("DATA IS NULL!");
        }
        return mJsonData;
    }

    //清空数组
    public void clearData(){
        ENTITIES.clear();
    }

}
